<?php

namespace IDock\Insurance\JDAL\Request;

use IDock\IDock\IDockEnums;
use IDock\Insurance\JDAL\JDALEnums;
use IDock\Insurance\JDAL\Response\UploadFileResponse;
use IDock\Visitor\UploadFileVisitor;

class UploadFileRequest extends AllJDALRequest
{
    public $route = 'document/uploadImages';

    public $requestCode = 'imagesUploadRequest';

    protected $response = UploadFileResponse::class;

    protected $urlTip = '影像上传';

    protected $inLog = true;

    /*** @var  UploadFileVisitor $visitor */
    protected $visitor;

    public function generate(): array
    {
        $this->partnerRef = $this->visitor->argc['channelCode'] ?? '';

        $data = [
            'comCode' => $this->visitor->argc['comCode'] ?? '',
            'businessNo' => $this->visitor->inquiryNo,
            'operatorName' => '',
            'applicantId' => '',
            'imgBatchUploadMetas' => []
        ];

        foreach ($this->visitor->getFileList() as $value) {
            $fileName = $value['url'] ?? '';

            $fileExt = substr(strrchr($fileName, "."), 0);

            $item = [
                'imgType' => JDALEnums::$uploadFileType[$value['type']],
                'base64FileContent' => $value['base64'] ?? '',
                'covered' => '0',
                'fileName' => IDockEnums::$uploadFileType[$value['type']] . $fileExt,
            ];

            $data['imgBatchUploadMetas'][] = $item;
        }

        return $data;

    }
}
